package com.han_meng_fei_sha.shoujixinxi;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.text.method.ScrollingMovementMethod;
import android.view.Display;
import android.view.WindowManager;
import android.widget.TextView;
//手机信息
//显示 手机信息 比如 手机型号，手机可用内存
//显示 手机 安装的应用  这个 功能 不需要 .  用户可以看到。  要做没有的。 这个代码 对开发 有用。

public class MainActivity extends Activity {
    TextView mTextView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
        StringBuffer sb = new StringBuffer();
        sb.append("\nDeviceId(IMEI) = " + tm.getDeviceId());
        sb.append("\nDeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion());
        sb.append("\nLine1Number = " + tm.getLine1Number());
        sb.append("\nNetworkCountryIso = " + tm.getNetworkCountryIso());
        sb.append("\nNetworkOperator = " + tm.getNetworkOperator());
        sb.append("\nNetworkOperatorName = " + tm.getNetworkOperatorName());
        sb.append("\nNetworkType = " + tm.getNetworkType());
        sb.append("\nPhoneType = " + tm.getPhoneType());
        sb.append("\nSimCountryIso = " + tm.getSimCountryIso());
        sb.append("\nSimOperator = " + tm.getSimOperator());
        sb.append("\nSimOperatorName = " + tm.getSimOperatorName());
        sb.append("\nSimSerialNumber = " + tm.getSimSerialNumber());
        sb.append("\nSimState = " + tm.getSimState());
        sb.append("\nSubscriberId(IMSI) = " + tm.getSubscriberId());
        sb.append("\nVoiceMailNumber = " + tm.getVoiceMailNumber());

        mTextView = (TextView) findViewById(R.id.textView);
        mTextView.setMovementMethod(new ScrollingMovementMethod());
        mTextView.setText(sb.toString());

        //制造商：
//        tvManufacturer.setText(getString(R.string.manufacturer) + PhoneInfo.getPhoneBrand());
//
//        //设备型号：
//        tvEquipmentModel.setText(getString(R.string.equipment_model) + PhoneInfo.getPhoneModel());
//
//        //设备分辨率
//        tvDeviceResolution.setText(getString(R.string.device_resolution) + PhoneInfo.getMetrics()[0] + "x" +
//                PhoneInfo.getMetrics()[1]);
//
//        //ISDN:
//
//        tvMobileIsdn.setText(getString(R.string.mobile_isdn) + PhoneInfo.getTelephonyManager().getLine1Number());
//
//        //IMEI
//
//        tvMobileImei.setText(getString(R.string.mobile_imei) + PhoneInfo.getTelephonyManager().getDeviceId());
//
//        //IMSI
//
//        tvMobileImsi.setText(getString(R.string.mobile_imsi) + PhoneInfo.getTelephonyManager().getSubscriberId());
//
////SIM卡串号
//
//        tvSimNumber.setText(getString(R.string.sim_number) + PhoneInfo.getTelephonyManager().getSimSerialNumber;
    }

    /**
     * 获取屏幕分辨率
     *
     * @return
     */
    public static int[] getMetrics(Context context) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point point = new Point();
        display.getSize(point);
        int width = point.x;
        int height = point.y;
        int[] metrics = {width, height};
        return metrics;
    }

    /**
     * 设备厂商
     *
     * @return
     */
    public static String getPhoneBrand() {
        return Build.BOARD + "  " + Build.MANUFACTURER;
    }

    /**
     * 设备名称
     *
     * @return
     */
    public static String getPhoneModel() {
        return Build.MODEL;
    }

    /**
     * 得到软件版本号
     *
     * @param context 上下文
     * @return 当前版本Code
     */
    public static int getVerCode(Context context) {
        int verCode = -1;
        try {
            String packageName = context.getPackageName();
            verCode = context.getPackageManager()
                    .getPackageInfo(packageName, 0).versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return verCode;
    }

    /**
     * 获得APP名称
     *
     * @param context
     * @return
     */
    public static String getAppName(Context context) {
        String appName = "";
        try {
            PackageManager packageManager = context.getPackageManager();
            ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
            appName = (String) packageManager.getApplicationLabel(applicationInfo);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return appName;
    }

}
